﻿app.controller('addWXCardCtrl', ['$scope', '$http', '$stateParams', '$filter', 'utils', 'httpPlus', function ($scope, $http, $stateParams, $filter, utils, httpPlus) {
    utils.setTitle('领取微信卡券');

    var currUrl = location.href.split('#')[0];
    //获取微信jssdk配置信息
    httpPlus
          .MMB2RRRApi("PyramidSellingBLL/InitWeChatMemberInvitePage", {
              _currUrl: currUrl
          }, 'wechat')
          .then(function (data) {
              //注入权限验证配置
              wx.config(data.JsConfig);
              return httpPlus
                      .MMB2RRRApi('WXCouponManage/AddCoupon', {
                          _cardID: $stateParams.cardID
                      })
              wx.error(function (res) {
                  alert(JSON.stringify(res));
              });
          })
           .then(function (data) {
               console.log(data.AddCardExt);
               wx.ready(function () {
                   wx.addCard({
                       cardList: data.AddCardExt,
                       success: function (res) {
                           alert("领取成功,请到微信卡包查看");
                       },
                       cancel: function (res) {
                           window.close();
                       }
                   });
               });
               wx.error(function (res) {
                   alert(JSON.stringify(res));
               });


           }, function (error) {
               alert(JSON.stringify(error));
           })
}])